
<style type="text/css">
#main { text-align: center; }
#main table { width: 560px; border: 1px solid #F8F8FF; margin: 0 auto; background-color: #F5FFFA }
#main table tr { text-align: left; }
#main textarea { width: 200px; height: 86px;  }
#main table span { color: red; padding: 2px; font-weight: bold; }
#main #outline { color: blue; }
#main u { color: red; font-weight: bold; }
</style>

<div id="main">
<h1>短信通信</h1>
<p>该功能仅供私人使用，目前短信剩余条数：<u><%=@sms_count%></u></p>
<%= form_for(@sms, :url => {:action => 'sms_send'}) do |f| %>

<table cellpadding="3" border="1" style="border-collapse:collapse;" cellspacing="3">
	<tr>
		<th>短信内容：</th>
		<td><textarea maxlength="60" id="content" name="content"></textarea></td>
		<td>还能输入<span id="limit">60</span>个字</td>
	</tr>
	<tr>
		<th>手机号码：</th>
		<td><textarea id="nums" name="nums" style="width:120px; height:200px;">18637778958</textarea></td>
		<td>每行输入<span>1</span>个手机号码<br/>
			<br/>最多可输入<span>40</span>个号码
			<br/><br/>已经输入<span id="line">1</span>行了<br/><br/><span id="outline"></span>
		</td>
	</tr>
	<tr>
		<th>操作密码：</th>
		<td><input type="password" id="pass" name="pass" style="width:150px;" /></td>
		<td></td>
	</tr>
	<tr>
		<td colspan="3" align="center">
			<%= f.submit '发送短信', :id=>"btnSubmit", :class=>'btn btn-primary btn-large' %> &nbsp;&nbsp; 
			<input type="reset" value="重新填写" class="btn btn-large" />
		</td>
	</tr>
</table>
<% end %>
</div>

<script type="text/javascript">
$().ready(function(){
	$('#content').keyup(function(){
		var limit = 60 - ($(this).val().length);
		$('#limit').html(limit);
		$(this).val(QtoB($(this).val()));
	});

	$('#nums').keyup(function(){
		var arr = $(this).val().split('\n');
		$('#line').html(arr.length);
		$('#outline').html(arr.length > 40 ? '超出无效' : '');
		$(this).val(QtoB($(this).val()));
	});

	$('#btnSubmit').click(function(){
		var c1 = $('#content');
		var c2 = $('nums');
		var c3 = $('pass');
		if(c1.val() == '' || c2.val() == '' || c2.val() == '') {
			alert('表单填写不完整');
			return false;
		}
		return true;
	});

	<% if(flash['result'] != nil) %>
	alert("<%=flash['result']%>");
	<% end %>
});

function QtoB(value) {
    var str = value;
    var result = "";
    for (var i = 0; i < str.length; i++) {
        if (str.charCodeAt(i) == 12288) {
            result += String.fromCharCode(str.charCodeAt(i) - 12256);
            continue;
        }
        if (str.charCodeAt(i) > 65280 && str.charCodeAt(i) < 65375)
            result += String.fromCharCode(str.charCodeAt(i) - 65248);
        else result += String.fromCharCode(str.charCodeAt(i));
    }
    return result;
}
</script>
